package com.hw.protocol.tool.decode.hb;

import com.hw.protocol.tool.model.entity.hb.Leakage;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;

/**
 * @author : lihy
 * @date : 2023/11/3 10:40
 * description: 泄漏实时数据解码器
 */

public class LeakageDecode {

    private ByteBuf dataBuf;

    private Leakage leakage;

    public LeakageDecode(String devSerial, byte[] data) {
        this.dataBuf = Unpooled.wrappedBuffer(data);
        this.leakage = new Leakage();
        leakage.setDevSerial(devSerial);
    }

    public Leakage buildObject(){
        leakage.setTime(DecodeUtil.getTime(dataBuf));
        leakage.setValue(dataBuf.readFloatLE());
        leakage.setPress(dataBuf.readFloatLE());
        leakage.setLevelAlarm(dataBuf.readByte());
        leakage.setDip(dataBuf.readByte());
        leakage.setLidAlarm(dataBuf.readByte());
        leakage.setSignal(dataBuf.readByte());
        leakage.setUploadType(dataBuf.readByte());

        dataBuf.release();
        return leakage;
    }
}
